/********************************
 * Robinson Matrix Algorithm
 *
 * Copyright (C) 2009 CNRS
 * Author : Florent AVELLANEDA, Eugen CEPOI
 * Algorithm design : Victor CHEPOI, Morgan SESTON ( http://www.lif-sud.univ-mrs.fr/%7Echepoi/robinson_chepoi_seston.pdf )
 * 
 *
 * All rights reserved.
 *
 *   This file is part of Robinson Matrix Algorithm.
 *
 *   Robinson Matrix Algorithm is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Robinson Matrix Algorithm is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Robinson Matrix Algorithm.  If not, see <http://www.gnu.org/licenses/>.
 *
 ***********************************************************************************/

#ifndef ALGO_4SO6M7N5

#define ALGO_4SO6M7N5

#include <vector>
#include <set>
#include "Matrix.h"
class PartialOrder;

namespace Algo
{

	/**
	 * @brief The function to call to find the robinson matrix, the total order and the epsilon.
	 *
	 * @param dissimilarityMatrix - the base matrice we work on
	 * @param robinsonMatrix - the result matrix
	 * @param delta - the error
	 * @param fast - if true the algorithm will work faster, but with little less good resultats
	 * 
	 * @return The total order
	 */
    std::vector<unsigned int> fittingByRobinson( Matrix &dissimilarityMatrix, Matrix &robinsonMatrix, double &delta , bool fast);

    /** 
     * @brief The answer false or a 16epsilon-compatible total order
     * 
     * @param m matrix
     * @param epsilon epsilon
     * @param partialOrder partial order
     * @param totalOrder - the total order we seek for
     * @param fast - if true the algorithm will work faster, but with little less good resultats
     * @return The answer false or a 16epsilon-compatible total order
     */
    bool refine( std::set<unsigned int> &X, Matrix *m, PartialOrder *partialOrder, 
            std::vector<unsigned int> &totalOrder, double epsilon, bool first, bool fast );

    std::vector<double> getDelta(const Matrix *m);

    Matrix TotalOrder2RobinsonMatrix(const Matrix &m, std::vector<unsigned int> totalOrder, double &delta );
}

#endif /* end of include guard: ALGO_4SO6M7N5 */
